#include <iostream>
#include "CheckerBoard.h"
#include <windows.h>
#include <string.h>
using namespace std;

int main()
{
	CheckerBoard CB;
	bool done = false;
	char* temp = new char[4];
	int state = 0;
	int type = 0;
	cout << "a.Player VS Player\nb.Player VS Computer\nc.Computer VS Computer" << endl;
	cin >> temp;
	if (temp[0]=='a'){state=0;}
	else if (temp[0]=='b'){state=1;}
	else if (temp[0]=='c'){state=2;}
	
	cout << "a.Greedy by Eat and Number of Pawn Move \nb.Greedy by Eat and King Move\n" << endl;
	cin >> temp;
	if (temp[0]=='a'){type=0;}
	else if (temp[0]=='b'){type=1;}
	
	while (!done)
	{
		CB.checkEat(CB.turn);	// Ngisi List Eat
		printf("Eat : \n");
		printList(CB.LoEat);
		CB.checkSafe(CB.turn);  // Ngisi List Danger
		printf("Danger : \n");
		printList(CB.LoDanger);
		printf("Jump : \n");
		printList(CB.LoJump);
		
		if (CB.checkMove(CB.turn) || !isEmpty(CB.LoEat)){
			if (CB.turn == CB.WHITE)
			{
				cout << "turn = WHITE" << endl;
			}
			else
			{
				cout << "turn = BLACK" << endl;
			}
			
			if (!isEmpty(CB.LoEat))
			{
				cout << "FORCE EAT" << endl;
			}
			else 
			{
				cout << "FREE MOVE" << endl;
			}
			
			CB.printBoard();
			if (CB.turn==CB.WHITE && state != 2) // Player White
				{
				cin >>  temp;	
				CB.move(temp[0]-48,temp[1]-48,temp[2]-48,temp[3]-48);
				}
			else if (CB.turn==CB.BLACK && state==0) // Player Black
				{
				cin >>  temp;	
				CB.move(temp[0]-48,temp[1]-48,temp[2]-48,temp[3]-48);
				}
			else 
				{
				CB.moveAI(type);
				}
			
			CB.countNumberOfPawn();
			if (CB.numberOfPawn1 == 0 || CB.numberOfPawn2 == 0) {done = true;}
		} else {
			done = true;
			if (CB.turn==CB.WHITE){
				CB.numberOfPawn1 = 0;
			} else {
				CB.numberOfPawn2 = 0;
			}
		}		
		system("pause");
		clearList(&CB.LoJump);
		clearList(&CB.LoEat);
		clearList(&CB.LoDanger);
	}
	CB.printBoard();
	if (CB.numberOfPawn1==0) {cout << "Player2 WIN" << endl;}
	if (CB.numberOfPawn2==0) {cout << "Player1 WIN" << endl;}
	return 0;
}
